<div class="container">
    <div class="crumbs">
        <ul id="breadcrumbs" class="breadcrumb">
            <li><i class="icon-home"></i> <a href="layout.php">Products</a></li>
            <li class="current"><a href="pages_calendar.html" title=""><?php echo $product[0]->name; ?></a></li>
        </ul>
    </div>
    <div class="page-header">
        <div class="page-title"><h3><?php echo $product[0]->name; ?></h3></div>
    </div>
    <div class="row">
        <div class="col-md-6">
            <dl class="dl-horizontal">
                <dt>Product ID</dt>
                <dd><?php echo $product[0]->id; ?></dd>
                <dt>Author</dt>
                <dd><?php echo $product[0]->user_name; ?></dd>
                <dt>Description</dt>
                <dd><?php echo $product[0]->content; ?></dd>
                <dt>Price</dt>
                <dd><?php echo '$' . $product[0]->price; ?></dd>
                <dt>Posted time</dt>
                <dd id="posted_time"><?php echo $product[0]->posted_time; ?></dd>
                <dt>Category</dt>
                <dd><?php echo $product[0]->category_name; ?></dd>
                <dt>Tags</dt>
                <dd id="tag">
                    <?php
                    foreach ($tags as $tag) {
                        echo $tag->name . ', ';
                    }
                    ?></dd>
                <dt>Censored</dt>
                <dd>
                    <form id="f">
                        <div class="make-switch switch-mini" data-on-label="<i class='icon-ok'></i>"
                             data-off-label="<i class='icon-remove'></i>">

                            <input name="censored" id="censored"
                                   type="checkbox" <?php if ($product[0]->censored) echo 'checked'; ?>
                                   class="toggle"/>

                        </div>
                        <input hidden="hidden" name="id" id="id" value="<?php echo $product[0]->id; ?>">
                    </form>
                </dd>
                <dt>Link in Graphic Land</dt>
                <dd><a href="http://localhost/item/<?php echo $product[0]->id ?>">Click here</a></dd>
            </dl>
        </div>
        <div class="col-md-6">
            <img src="<?php if ($images[0]->thumbnail == 1) echo $images[0]->url; ?>">
        </div>
    </div>
    <div class="row">
        <?php
        foreach ($images as $image) {
            if ($image->thumbnail == 1)
                continue;
            echo '<div class="col-sm-6 col-md-3">' .
                '<div class="statbox widget box box-shadow">' .
                '<div class="widget-content">' .
                '<img style="height: 115px" src="' . $image->url . '"/>' .
                '</div>' .
                '</div>' .
                '</div>';
        }
        ?>
    </div>
</div>
<script>
    d = new Date(parseInt($('#posted_time').html()));
    day = d.getDate() + '/' + eval(d.getMonth() + 1) + '/' + d.getFullYear() + ' at ' + d.getHours() + ':' + d.getMinutes();
    $('#posted_time').html(day);
    tag = $('#tag').html();
    $('#tag').html(tag.substr(0, tag.length - 2));
    $('#f').submit(function () {
        $.post('http://localhost/admin/product/update_censored', $(this).serialize())
            .done(function (data) {
                if (parseInt(data) == 1) {
                    $('.row').eq(0).prepend("<div class='alert alert-info fade in'> " +
                        "<i class='icon-remove close' data-dismiss='alert'></i>" +
                        " Successfully. </div>");
                }
                else {
                    $('.row').eq(0).prepend("<div class='alert alert-danger fade in'> " +
                        "<i class='icon-remove close' data-dismiss='alert'></i>" +
                        " Unsuccessfully. </div>");
                }
                setTimeout(function () {
                    location.reload();
                }, 1000)
            });
        return false;
    })
    $('#censored').change(function () {
        $('#f').submit();
    });
</script>